//
//  ZXTabBar.swift
//  Swift_WeiBo
//
//  Created by dajie on 15/8/18.
//  Copyright (c) 2015年 dajie. All rights reserved.
//

import UIKit

class ZXTabBar: UITabBar
{

    override func layoutSubviews() {
        super.layoutSubviews()
        
        let btnCount = 5
        let btnWidth = bounds.size.width / CGFloat(btnCount)
        let btnHeight = bounds.size.height
        var index = 0 as CGFloat
        for v in subviews as! [UIView]
        {
            if v is UIControl && !(v is UIButton)
            {
                v.frame = CGRectMake(index * btnWidth, 0, btnWidth, btnHeight)
                index++
                index += (index == 2) ? 1 : 0
            }
        }
        self.composeButton.frame = CGRectMake(self.center.x - btnWidth * 0.5, self.bounds.origin.y, btnWidth, btnHeight)
    }

// MARK: - 添加懒加载发送按钮
    lazy var composeButton : UIButton = {
       
        var composeBtn = UIButton()
        composeBtn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        composeBtn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        composeBtn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        composeBtn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        self.addSubview(composeBtn)  //这里是闭包，是提前准备的代码，所以必须要用self
        return composeBtn
    }()
}
